package xju_9_10.springboot_9_10.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import xju_9_10.springboot_9_10.entity.Friend;

@Controller
public class UserController {

    @Value("${friend.username}")
    private String name;
    @Value("${friend.age}")
    private String age;
    @Value("${pet[0]}")
    private String pet;

    @Autowired
    private Environment environment;

    @Autowired
    private Friend friend;


    @GetMapping("/test")
    @ResponseBody
    public String test(@RequestParam(value = "username",required = false,defaultValue = "hello")  String username) {
        System.out.println(name);
        System.out.println(age);
        System.out.println(pet);
        System.out.println("---------");
        System.out.println(environment.getProperty("friend.username"));
        System.out.println(environment.getProperty("friend.age"));
        System.out.println(environment.getProperty("pet[0]"));
        System.out.println(friend);
        return "test"+username;
    }
}
